package com.example.cores_activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ActionActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_action);

        findViewById(R.id.btn_dial).setOnClickListener(this);
        findViewById(R.id.btn_sms).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        // 创建意图
        Intent intent = new Intent();
        int phoneNum = 132456;

        boolean isDial = view.getId() == R.id.btn_dial;
        boolean isSMS = view.getId() == R.id.btn_sms;

        if (isDial) {
            // 设置动作
            intent.setAction(Intent.ACTION_DIAL);
            // 创建数据
            Uri uri = Uri.parse("tel:" + phoneNum);
            // 设置数据
            intent.setData(uri);
            // 开始活动
            startActivity(intent);
        } else if (isSMS) {
            intent.setAction(Intent.ACTION_SENDTO);
            Uri uri = Uri.parse("smsto:" + phoneNum);
            intent.setData(uri);
            startActivity(intent);
        }
    }
}